<template>
  <el-cascader
    :value="value"
    placeholder="搜索"
    :options="options"
    filterable
    @input="inputHandle"
  />
</template>

<script>
import { initData } from '@/api/data'

export default {
  props: {
    value: {
      default: null,
      type: Number,
      required: false
    }
  },
  data() {
    return {
      rules: {
        id: [
          { required: true, message: '不能为空', trigger: 'blur' }
        ]
      },
      empAll: [],
      options: []
    }
  },
  created() {
    this.searchEmp()
  },
  methods: {
    searchEmp() {
      // todo 下拉菜单考虑在后台返回一个简单对象
      return new Promise((resolve, reject) => {
        // 请求数据
        initData('api/projectBase',
          { page: -1, size: 99999, sort: 'id,asc' }
        ).then(data => {
          // 获得数据
          this.empAll = data.content
          resolve(data)
          for (var t = 0; t < this.empAll.length; t++) {
            this.options.push({ 'value': this.empAll[t].id, 'label': this.empAll[t].projectName })
          }
        }).catch(err => {
          reject(err)
        })
      })
    },
    inputHandle(e) {
      // console.log(e)
      this.$emit('input', e[0])
    }
  }
}
</script>

<style scoped>

</style>
